import { expect } from "chai";
// const { ethers } = require("hardhat")


export function shouldBehaveUintBlog(): void {
    let initialblogName = "My blog"
    
    it("Should create a post", async function () {
        const blogTitle = "My first post"
        const contentHash = await this.blog.getRandomBytes32("12345")

        await this.blog.createPost(blogTitle, contentHash)
    
        const posts = await this.blog.fetchPosts()
    
        //this is the first post, so it is posts[0]
        expect(posts[0].title).to.equal(blogTitle)
        expect(posts[0].contentHash).to.equal(contentHash)
        // expect(posts[0].id).to.equal(contentHash)
      })  
    
      it("Should create 3 post with incremental id", async function () {
        const contentHash = this.blog.getRandomBytes32("111")
        const contentHash2 = this.blog.getRandomBytes32("222")
        const contentHash3 = this.blog.getRandomBytes32("333")
    
        await this.blog.createPost("My first post", contentHash)
        await this.blog.createPost("My second post", contentHash2)
        await this.blog.createPost("My third post", contentHash3)
    
        const posts = await this.blog.fetchPosts()
    
        expect(posts[0].title).to.equal("My first post")
        // expect(posts[0].id).to.equal(1)
    
        expect(posts[1].title).to.equal("My second post")
        // expect(posts[1].id).to.equal(2)
    
        expect(posts[2].title).to.equal("My third post")
        // expect(posts[2].id).to.equal(3)
      })
    
      it("Should edit a post", async function () {
        const blogTitle = "My first post"
        const contentHash =await this.blog.getRandomBytes32("111")
        const newBlogTitle = "My updated post"
        const newContentHash = await this.blog.getRandomBytes32("222")
    
        await this.blog.createPost(blogTitle, contentHash)
    
        //change title and contentHash 
        await this.blog.updatePost(1, newBlogTitle, newContentHash, true)
    
        let posts = await this.blog.fetchPosts()
        expect(posts[0].title).to.equal(newBlogTitle)
        expect(posts[0].contentHash).to.equal(newContentHash)
      })
    
      it("Should update the blog name by owner", async function () {
        const newBlogName = "My new blog"
        expect(await this.blog.name()).to.equal(initialblogName)
        await this.blog.updateName(newBlogName)
        expect(await this.blog.name()).to.equal(newBlogName)
      })
    
      it("Should revert to update the blog name not by owner", async function () {
        const newBlogName = "My new blog"
        expect(await this.blog.name()).to.equal(initialblogName)
        await expect(this.blog.connect(this.signers.user).updateName(newBlogName)).to.be.reverted
      })
    
      it("Should transfer owner successfuly and update name by new owner", async function () {
        expect(await this.blog.name()).to.equal(initialblogName)
    
        await this.blog.transferOwnership(await this.signers.admin.getAddress())
    
        const newBlogName = "My new blog"
        await this.blog.connect(this.signers.admin).updateName(newBlogName)
        expect(await this.blog.name()).to.equal(newBlogName)
      })
}